<?php
         define('ACC', true);
require('./include/init.php');

session_start(); 
//print_r($_SESSION);
$userid = $_SESSION['user_id'];

echo '<head><meta charset = "utf-8"></head>';  
//$userid = 26;
 echo '<h2>采购&nbsp&nbsp<a href = "dashboard.php">返回虚拟公司主页</a></h2><br/>';   

$company = new companymodel();
$companyinfo = $company->getcompanyinfo($userid);
$companyid = $companyinfo['company_id'];

echo '<h2>公司名称为:' . $companyinfo['company_name'], '&nbsp|&nbsp';
echo '目前所在财年:第' . $companyinfo['company_y'] . '财年', '&nbsp|&nbsp';
echo '目前所在季度:第' . $companyinfo['company_q'] . '季度', '</h2><br/><br/><br/>';


$loaninfo = $company->getallelements($companyid, 'loan');  
$loanlist = $company->getelementlist('loan');


echo '<h4>目前可供选择的贷款有以下' . count($loanlist) . '种：</h4>';
echo '<form name="loan" action="applyforloanAct.php" method="post"><table border = "1">
          <tr><td>贷款类别</td><td>利率</td><td>期限(季度)</td><td>已有金额</td><td>申请贷款金额输入</td> </tr>';
foreach($loanlist  as $k=>$v){
    $loanname = $v['element_name'];
    $duration =  $v['duration'];
    $interestrate = $v['interest_rate'];
    
    $amountofloan = 0;
    
    foreach($loaninfo as $key =>$value){
         if($value['element_id'] == $v['element_id']){
             $amountofloan = $amountofloan + $value['current_value'];
         } 
    }                                                                                                                                                                           
    echo'<tr><td>' . $loanname . '</td><td>' . $interestrate . '</td><td>' . $duration . '</td><td>' .  $amountofloan .  '</td><td><input type="text" name="' . $loanname. '" /></td></tr>' ;
}          
      
echo '</table>
<input type = "hidden" name="type" value="loan">
<input type = "submit" value = "提交"></form><br/>';


?>
